import { createRouter, createWebHistory, type RouteRecordRaw } from 'vue-router'

const fileList: string[] = [
  'brothers', 
  'directiveDemo', 
  'dynamicComponent', 
  'mittDemo', 
  'provideDemo', 
  'slotUse', 
  'syncComponent', 
  'teltportDemo',
  'useLoading',
  'hRender'
]

// 根据views下的文件名，自动创建路由，识别规则：文件夹名为路由名，文件夹下必须包含要给index.vue。访问页面直接使用'/文件名'即可
const getRouterByfilename = (): RouteRecordRaw[] => {
  let resList: Array<RouteRecordRaw> = []

  fileList.forEach(item => {
    resList.push({
      path: `/${item}`,
      name: item,
      component: () => import(`../views/${item}/index.vue`)
    })
  })

  return resList
}

const routersForFiles = getRouterByfilename()

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: routersForFiles
})

export default router
